package com.hctforgreen.greenservice.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 3、所有资料类别信息
 * @author Tallen Zhai
 *
 */
public class BookTypeListEntity extends BaseEntity {

	private static final long serialVersionUID = -6369655887298214108L;

	public List<BookTypeEntity> dataList = null;
	
	public String statusCode = "";
	public String msg = "";
	public final static String STATUS_CODE = "statusCode";
	public final static String MSG = "msg";
	private final static String BOOK_TYPES = "booktypes";
	
	public static BookTypeListEntity parse(JSONObject jsonObject)throws JSONException{
		BookTypeListEntity bean = new BookTypeListEntity();
		if(jsonObject.has(STATUS_CODE)){
			bean.statusCode = jsonObject.getString(STATUS_CODE);
		}
		if(jsonObject.has(MSG)){
			bean.msg = jsonObject.getString(MSG);
		}
		/**
		 * 解析booktypes节点
		 */
		if (jsonObject.has(BOOK_TYPES)) {
			
			JSONArray jsonArray = jsonObject.getJSONArray(BOOK_TYPES);
				
			bean.dataList = new ArrayList<BookTypeEntity>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject object = jsonArray.getJSONObject(i);
				BookTypeEntity entity = BookTypeEntity.parse(object);
				bean.dataList.add(entity);
			}
			
		}
		
		return bean;
	}
	public static class BookTypeEntity extends BaseEntity {

		private static final long serialVersionUID = 6265669583798259579L;
		public String name = "";
		public String id = "";
		
		public final static String NAME = "name";
		public final static String ID = "id";
		
		public static BookTypeEntity parse(JSONObject jsonObject)
				throws JSONException {
			BookTypeEntity bean = new BookTypeEntity();
			if (jsonObject.has(NAME)) {
				bean.name = jsonObject.getString(NAME);
			}
			if (jsonObject.has(ID)) {
				bean.id = jsonObject.getString(ID);
			}
			return bean;
		}
	}
}
